<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
      定义dp数组和下标含义： dp[i][j]表示长度为i，以nums[i-1]为下标的子数组nums1和长度为j的子数组nums2的最长公共子数组
      ②状态转移方程
      if(nums[i-1]==nums2[j-1]) dp[i][j]=dp[i-1][j-1]+1

      */
      var findLength = function (nums1, nums2) {
        let max = 0
        let dp = new Array(nums1.length + 1).fill().map(() => new Array(nums2.length + 1).fill(0))
        for (let i = 1; i <= nums1.length; i++) {
          for (let j = 1; j <= nums2.length; j++) {
            if (nums1[i - 1] == nums2[j - 1]) {
              dp[i][j] = dp[i - 1][j - 1] + 1
              max = Math.max(dp[i][j], max)
            }
          }
        }
        return max
      }
    </script>
  </body>
</html>
